<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:s="http://jboss.org/schema/seam/taglib"
  xmlns:a4j="http://richfaces.org/a4j"
  template="../WEB-INF/template/template.xhtml">

  <ui:define
    name="page_title">#{msgs['jsf.Profile']}:#{msgs['jsf.NewUser.Label']}</ui:define>

  <ui:define name="center_content">
    <div class="g--centered">
      <div class="g__item w--1-2-m w--3-8-l w--1-3 l--push-bottom-1">

        <s:link view="/account/register.xhtml"
          propagation="none"
          rendered="#{applicationConfiguration.internalAuth}">
          <p class="txt--meta l--push-all-0">#{msgs['jsf.Signup']}</p>
        </s:link>

        <s:fragment
          rendered="#{not applicationConfiguration.internalAuth and not empty applicationConfiguration.registerPath}">
          <a href="#{applicationConfiguration.registerPath}">
            <p class="txt--meta l--push-all-0">#{msgs['jsf.Signup']}</p>
          </a>
        </s:fragment>

        <h1 class="l--push-all-0">#{msgs['jsf.NewUser.Label']}</h1>

        <div class="txt--meta">
          <h:outputText value="#{msgs['jsf.FirstExternalLoginMessage']}"
            rendered="#{authenticationManager.newUser}"/>
        </div>


        <h:form id="profile-form">
          <div class="l--push-top-half form__item">
            <h:outputLabel for="name">#{msgs['jsf.Name']}
              <s:span styleClass="txt--required">*</s:span>
            </h:outputLabel>
            <s:decorate id="nameField" template="../WEB-INF/layout/field.xhtml" enclose="true">
              <h:inputText id="name" value="#{newProfileAction.name}" required="true"
                maxlength="80">
                <a4j:ajax event="blur" render="nameField" execute="@this"/>
              </h:inputText>
            </s:decorate>
          </div>

          <ui:remove>
            <!-- User name field is only shown for new users (otherwise they aren't allowed to edit the user name) -->
          </ui:remove>
          <s:div styleClass="l--push-top-half form__item">
          <h:outputLabel for="username">#{msgs['jsf.Username']}
              <s:span styleClass="txt--required">*</s:span>
            </h:outputLabel>
            <s:decorate id="usernameField" template="../WEB-INF/layout/field.xhtml" enclose="true">
              <h:inputText id="username" required="true" maxlength="80"
                value="#{newProfileAction.username}">
                <a4j:ajax event="blur" render="usernameField" execute="@this"/>
              </h:inputText>
            </s:decorate>
          </s:div>

          <div class="l--push-top-half form__item">
            <h:outputLabel for="email">
              #{msgs['jsf.Email']}
            </h:outputLabel>
            <s:decorate id="emailField" template="../WEB-INF/layout/field.xhtml">
              <h:inputText id="email" required="false"
                value="#{newProfileAction.email}">
                <a4j:ajax event="blur" render="emailField" execute="@this"/>
              </h:inputText>
            </s:decorate>
          </div>

          <s:fragment rendered="#{not empty applicationConfiguration.termsOfUseUrl}">
            <p class="txt--meta l--push-top-half">
              <h:outputText value="#{msgs.format('jsf.register.agreeToTOS',
                applicationConfiguration.termsOfUseUrl)}" escape="false"/>
            </p>
          </s:fragment>

          <div class="l--push-top-1">
            <h:commandButton id="user-create-new"
              value="#{msgs['jsf.Save']}"
              action="#{newProfileAction.createUser}"
              styleClass="l--push-right-half button--primary"/>
            <s:button id="user-create-cancel" styleClass="button button-link"
              value="#{msgs['jsf.Cancel']}"
              action="#{newProfileAction.cancel}"/>
          </div>
        </h:form>
      </div>
    </div>
  </ui:define>
</ui:composition>
